// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item {
    id: car_navi
    width: 400
    height: 500

    property string drive_type: "0"
    property string drive_type_name: "速度优先"

//    Rectangle {
//        id: rectangle_bg
//        color: "#002e93"
//        anchors.fill: parent
//    }

    function hide()
    {
        mmultitext1.hide();
    }

    MMultiText {
        id: mmultitext1
        x: 0
        title_text: "起点与终点"
        anchors.top: parent.top
        anchors.topMargin: 5
        anchors.right: parent.right
        anchors.rightMargin: 0

        text_0: "起点："
        text_1: "终点："
        address_0: data_map.start_name
        address_1: data_map.end_name

        onBt0_click: backend.show_message("帮助", "请在地图点击右键选择<b>起点</b> <br><br>或在位置搜索中选择<b>起点</b>");
        onBt1_click: backend.show_message("帮助", "请在地图点击右键选择<b>终点</b> <br><br>或在位置搜索中选择<b>终点</b>");
    }

    Mbutton {
        id: mbutton2
        x: 25
        anchors.top: mmultitext1.bottom
        anchors.topMargin: 10
        textstring: "当前搜索策略：" + drive_type_name
        text_size: 26
        pro_height: 50
        pro_width: 350

        onButtonclick:
        {
            loader_type.load();
        }
    }

    Mbutton {
        id: mbutton1
        x: 175
        y: 247
        text_size: 30
        textstring: "开始搜索"
        anchors.top: mbutton2.bottom
        anchors.topMargin: 10
        anchors.right: parent.right
        anchors.rightMargin: 25
        pro_height: 50

        onButtonclick:
        {
            backend.car_navi(data_map.start_x, data_map.start_y, data_map.end_x, data_map.end_y, drive_type);
        }
    }

    Item {
        id: item_result
        anchors.right: parent.right
        anchors.rightMargin: 15
        anchors.left: parent.left
        anchors.leftMargin: 15
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 20
        anchors.top: mbutton1.bottom
        anchors.topMargin: 10

        ListView {
            id: list_view_result
            x: 0
            width: parent.width
            spacing: 5
            clip: true
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 0
            anchors.top: parent.top
            anchors.topMargin: 0
            delegate: Item {
                x: 5
                height: text_drive_info.paintedHeight > 44 ? text_drive_info.paintedHeight + 5 : 44
                width: parent.width

                //                        MouseArea
                //                        {
                //                            anchors.fill: parent
                //                            onClicked:
                //                            {
                //                                car_navi.state == "" ? car_navi.state = "detail" : car_navi.state = "" ;
                //                            }
                //                        }

                Row {
                    id: row1
                    spacing: 10

                    Rectangle {
                        width: 40
                        height: 40
                        color: "#00000000"
                        border.color: "lightblue"
                        border.width: 2
                        radius: 40
                        smooth: true
                        anchors.verticalCenter: parent.verticalCenter

                        Text
                        {
                            anchors.centerIn: parent
                            color: "white"
                            font.pixelSize: 18
                            text: index + 1
                        }
                    }

                    Text
                    {
                        id: text_drive_info
                        text: textInfo
                        width: list_view_result.width - 50
                        anchors.verticalCenter: parent.verticalCenter
//                        font.bold: true
                        font.pixelSize: 22
                        color: "white"
//                        elide: Text.ElideRight
                        wrapMode: Text.WrapAtWordBoundaryOrAnywhere
                    }

//                    Text {
//                        text: textInfo
//                        anchors.verticalCenter: parent.verticalCenter
//                        font.bold: true
//                        color: "white"
//                    }


                }
            }
            model: data_map.get_model_car()
        }

        Item {
            id: item_detail
            width: parent.width
            anchors.left: list_view_result.right
            anchors.leftMargin: 20
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 0
            anchors.top: parent.top
            anchors.topMargin: 0

//            Rectangle {
//                id: rectangle1
//                x: 39
//                y: 66
//                width: 200
//                height: 200
//                color: "#ffffff"

//                MouseArea {
//                    id: mouse_area1
//                    anchors.fill: parent

//                    onClicked:
//                    {
//                        poi_search.state == "" ? poi_search.state = "detail" : poi_search.state = "" ;
//                    }
//                }
//            }
        }
    }

    Loader
    {
        id: loader_type
        anchors.fill: parent
        source: ""

        function load()
        {
            source = "TypeChoose.qml";
        }

        function unload()
        {
            source = "";
        }
    }

    Connections
    {
        id: conn_type
        target: loader_type.item

        onDrive_type:
        {
            drive_type = typecode;
            drive_type_name = typename;
            loader_type.unload();
        }
    }

    states: [
        State {
            name: "detail"

            PropertyChanges {
                target: list_view_result
                x: -width -20
            }
        }
    ]

}
